import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_time_period.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/data/entities/application/smart_warehouse/in_out_record_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/smart_warehouse/outbound_records/outbound_records_controller.dart';

/// 出库记录页面
class OutboundRecordsPage extends StatelessWidget {
  OutboundRecordsPage({super.key});

  final controller = Get.put(OutboundRecordsController());

  ///左侧名称-右侧内容-左右布局
  ///[title]名称
  ///[content]内容
  Widget _getLeftNameRightContent({
    String title = '',
    String content = '',
  }) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          title,
          style: TextStyle(fontSize: 13.sp, fontWeight: FontWeight.w400, height: 1.2, color: const Color(0xffA0A7B5)),
        ),
        Expanded(
            child: Text(
          content,
          style: TextStyle(
            fontSize: 13.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xff495061),
          ),
        ))
      ],
    );
  }

  ///出库信息列表项
  Widget _getOutboundInformationView(InOutRecordEntity item) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 14.w),
      decoration: BoxDecoration(
        color: const Color(0xffffffff),
        borderRadius: BorderRadius.circular(12.r),
      ),
      child: Column(
        children: [
          Row(
            children: [
              Container(
                height: 14.w,
                width: 3.w,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(topRight: Radius.circular(90.w), bottomLeft: Radius.circular(20.w), bottomRight: Radius.circular(20.w)),
                  gradient: LinearGradient(
                      //渐变位置
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      //渐变颜色[始点颜色, 结束颜色]
                      colors: [const Color(0xff587DF5), const Color(0xff587DF5), const Color(0xff587DF5).withOpacity(0.6)]),
                ),
              ),
              AppGaps.hGap10,
              Expanded(
                child: Text(
                  '产品名称：${item.productName}',
                  maxLines: 1,
                  style: TextStyle(
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w500,
                    color: const Color(0xff262F38),
                  ),
                ),
              ),
            ],
          ),
          AppGaps.vGap14,
          Container(
            alignment: Alignment.centerLeft,
            padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.w),
            decoration: BoxDecoration(
              color: const Color(0xffF5F6FA),
              borderRadius: BorderRadius.circular(4.r),
            ),
            child: Text(
              '编号 ：${item.recordNumber}',
              style: TextStyle(
                fontSize: 12.sp,
                fontWeight: FontWeight.w400,
                color: const Color(0xff5C6DFF),
              ),
            ),
          ),
          AppGaps.vGap14,
          Row(
            children: [
              Expanded(
                flex: 2,
                child: _getLeftNameRightContent(title: '出库人：', content: '${item.warehouseEntryAndExitPersonnelName}'),
              ),
              Expanded(
                flex: 3,
                child: _getLeftNameRightContent(title: '出库时间：', content: '${item.createDate}'),
              )
            ],
          ),
          AppGaps.vGap10,
          _getLeftNameRightContent(title: '出库明细：', content: '${item.productName} 从 ${item.warehouseName} 出库${item.recordNum}件')
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '产品出库记录',
            ),
            body: Container(
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 10.w),
              alignment: Alignment.center,
              color: const Color(0xFFF5F5F6),
              child: Column(
                children: [
                  CustomSelectTimePeriod(
                    startTime: controller.startTime,
                    endTime: controller.endTime,
                    onConfirm: (startTime, endTime) {
                      controller.startTime = startTime;
                      controller.endTime = endTime;
                      controller.refreshPage();
                      controller.update();
                    },
                  ),
                  AppGaps.vGap14,
                  Expanded(
                      child: CustomEasyRefreshList<InOutRecordEntity>(
                          key: controller.globalKey,
                          dataLoad: (pageNum, pageSize, {String? search}) {
                            return controller.getProductRecordsListData(pageNum, pageSize);
                          },
                          itemBuilder: (item, index) {
                            return _getOutboundInformationView(item);
                          }))
                ],
              ),
            ),
          );
        });
  }
}
